package com.wuyoucar.controller;


import com.wuyoucar.common.PageBean;
import com.wuyoucar.common.ResultBean;
import com.wuyoucar.entity.TPolicy;
import com.wuyoucar.entity.TReport;
import com.wuyoucar.mapper.TPolicyMapper;
import com.wuyoucar.service.IReportService;
import com.wuyoucar.service.InTBankService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.concurrent.TransferQueue;

@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    IReportService reportService;
    @Autowired
    private TPolicyMapper tPolicyMapper;
    @Autowired
    private InTBankService inTBankService;
    //提醒用户绑定银行卡
    @GetMapping("/reminduser/{policynum}")
    public ResultBean reminduser(@PathVariable("policynum")Integer policynum){
        TPolicy tPolicy = tPolicyMapper.queryPolicyno(policynum);
        ResultBean resultBean = inTBankService.selectAllCard(tPolicy.getUserid());
        if (resultBean.getCode() == 404){
            //用户尚未绑定银行卡 提醒绑定;
            return new ResultBean(200,"提醒成功");
        }else{
            return new ResultBean(404,"用户已绑定银行卡");
        }
    }
    //放款后修改状态
    @GetMapping("/paymoney/{money}/{reportid}/{policynum}")
    public ResultBean paymoney(@PathVariable("money") Double money,
                               @PathVariable("reportid") Integer reportid,
                               @PathVariable("policynum") Integer policynum){
        return reportService.updateState(money,reportid,policynum);
    }
    //待处理页面分页
    @GetMapping("/selectPage")
    public PageBean<TReport> selectTReportByPage(){
        return reportService.selectReportByPage();
    }
    //待处理页面分页1
    @GetMapping("/selectPage1/{pageIndex}/{pageSize}")
    public PageBean<TReport> selectTReportByPage(@PathVariable("pageIndex")Integer pageIndex,
                                                 @PathVariable("pageSize")Integer pageSize){
        return reportService.selectReportByPage(pageIndex,pageSize);
    }
    //查询分页
    @GetMapping("searchmoney/{pageIndex}/{pageSize}/{money1}/{money2}")
    public PageBean<TReport> searcByMoney(@PathVariable("pageIndex")Integer pageIndex,
                                          @PathVariable("pageSize")Integer pageSize,
                                          @PathVariable("money1")Double money1,
                                          @PathVariable("money2")Double money2
                                          ){
        return reportService.searchByMoney(pageIndex,pageSize,money1,money2);
    }
    //已放款页面分页
    @GetMapping("/selectByPage")
    public PageBean<TReport> selectPage(){
        return reportService.selectPage();
    }
    //已放款页面分页1
    @GetMapping("/selectByPage1/{pageIndex}/{pageSize}")
    public PageBean<TReport> selectByPage(@PathVariable("pageIndex")Integer pageIndex,
                                           @PathVariable("pageSize")Integer pageSize){
        return reportService.selectPage(pageIndex,pageSize);
    }

    //查询分页
    @GetMapping("searchmoney2/{pageIndex}/{pageSize}/{money1}/{money2}")
    public PageBean<TReport> searcByMoney2(@PathVariable("pageIndex")Integer pageIndex,
                                          @PathVariable("pageSize")Integer pageSize,
                                          @PathVariable("money1")Double money1,
                                          @PathVariable("money2")Double money2
    ){
        return reportService.searchByMoney2(pageIndex,pageSize,money1,money2);
    }
}
